#include "HounsfieldWindow.h"

HounsfieldWindow::HounsfieldWindow(QWidget *parent) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
{
	setWindowTitle("Set window boundaries");
	mMinValueField = new QLineEdit;
	mMaxValueField = new QLineEdit;
	QValidator *validator = new QIntValidator();
	mMinValueField->setValidator(validator);
	mMaxValueField->setValidator(validator);
	QString str;
	str.setNum(mMinValue);
	mMinValueField->setText(str);
	str.setNum(mMaxValue);
	mMaxValueField->setText(str);

	QLabel * mMinValueLabel = new QLabel("&Minimum");
	QLabel * mMaxValueLabel = new QLabel("&Maximum");
	mMinValueLabel->setBuddy(mMinValueField);
	mMaxValueLabel->setBuddy(mMaxValueField);
	QPushButton * ok = new QPushButton("&Ok");
	QPushButton * cancel = new QPushButton("&Cancel");

	connect(ok,SIGNAL(clicked()), SLOT(accept()));
	connect(ok,SIGNAL(clicked()), SLOT(slotAcceptValues()));
	connect(cancel,SIGNAL(clicked()), SLOT(reject()));

	QGridLayout * layout = new QGridLayout;
	layout->addWidget(mMinValueLabel, 0,0);
	layout->addWidget(mMaxValueLabel, 1,0);
	layout->addWidget(mMinValueField,0,1);
	layout->addWidget(mMaxValueField,1,1);
	layout->addWidget(ok, 2,0);
	layout->addWidget(cancel, 2,1);
	setLayout(layout);

}

HounsfieldWindow::~HounsfieldWindow(void)
{
}

int HounsfieldWindow::mMinValue = 0;
int HounsfieldWindow::mMaxValue = 0;

void HounsfieldWindow::setMinValue(int value)
{
	mMinValue = value;
}
int HounsfieldWindow::getMinValue()
{
	return mMinValue;
}
void HounsfieldWindow::setMaxValue(int value)
{
	mMaxValue = value;
}
int HounsfieldWindow::getMaxValue()
{
	return mMaxValue;
}
void HounsfieldWindow::setWindowValues(int min, int max)
{
	mMinValue = min;
	mMaxValue = max;
}

void HounsfieldWindow::setSoftWindow()
{
	mMinValue = SOFT_WINDOW_MIN;
	mMaxValue = SOFT_WINDOW_MAX;
}
void HounsfieldWindow::setBoneWindow()
{
	mMinValue = BONE_WINDOW_MIN;
	mMaxValue = BONE_WINDOW_MAX;
}

void HounsfieldWindow::slotAcceptValues()
{
	mMinValue = mMinValueField->text().toInt();
	mMaxValue = mMaxValueField->text().toInt();
}